//package com.ctz.commonframe.network;
//
//import java.util.Map;
//import java.util.concurrent.TimeUnit;
//
//import okhttp3.OkHttpClient;
//import retrofit2.Retrofit;
//import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
//import retrofit2.converter.gson.GsonConverterFactory;
//
//public class RetrofitServiceManager {
//    /**
//     * 默认连接超时时间
//     */
//    private static final int DEFAULT_TIME_OUT = 5;
//
//    /**
//     * 默认读操作超时时间
//     */
//    private static final int DEFAULT_READ_TIME_OUT = 10;
//
//    /**
//     * 默认写操作超时时间
//     */
//    private static final int DEFAULT_WRITE_TIME_OUT = 10;
//
//    private Retrofit mRetrofit;
//    private Retrofit.Builder mRetrofitBuilder;
//    private OkHttpClient.Builder mHttpClientBuilder;
//    private HttpHeaderInterceptor.Builder mHttpHeaderInterceptorBuilder;
//
//    public void init (int timeout, int readTimeout, int writeTimeout, String baseUrl, Map<String, String> headerParams) {
//        mHttpClientBuilder.connectTimeout(timeout > 0 ? timeout : DEFAULT_TIME_OUT, TimeUnit.SECONDS);
//        mHttpClientBuilder.writeTimeout(readTimeout > 0 ? readTimeout : DEFAULT_READ_TIME_OUT, TimeUnit.SECONDS);
//        mHttpClientBuilder.readTimeout(writeTimeout > 0 ? writeTimeout : DEFAULT_WRITE_TIME_OUT, TimeUnit.SECONDS);
//        HttpHeaderInterceptor headerInterceptor = mHttpHeaderInterceptorBuilder.addHeaderParams(headerParams).build();
//        mHttpClientBuilder.addInterceptor(headerInterceptor);
//        mRetrofit = mRetrofitBuilder
//                .client(mHttpClientBuilder.build())
//                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
//                .addConverterFactory(GsonConverterFactory.create())
//                .baseUrl(baseUrl)
//                .build();
//    }
//
//    public void init (String baseUrl, Map<String, String> headerParams) {
//        init(DEFAULT_TIME_OUT, DEFAULT_READ_TIME_OUT, DEFAULT_WRITE_TIME_OUT, baseUrl, headerParams);
//    }
//
//    private RetrofitServiceManager(){
//        mHttpClientBuilder = new OkHttpClient.Builder();
//        mHttpHeaderInterceptorBuilder = new HttpHeaderInterceptor.Builder();
//        mRetrofitBuilder = new Retrofit.Builder();
//    }
//
//    private static class SingletonHolder{
//        private static final RetrofitServiceManager INSTANCE = new RetrofitServiceManager();
//    }
//
//    /**
//     * 获取RetrofitServiceManager单例
//     *
//     * @return
//     */
//    public static RetrofitServiceManager getInstance(){
//        return SingletonHolder.INSTANCE;
//    }
//
//    /**
//     * 获取对应的Service
//     * @param api api 的 class
//     * @param <T>
//     * @return
//     */
//    public <T> T create(Class<T> api){
//        return mRetrofit.create(api);
//    }
//}
